welcome to our Matplotlib the second module specified in data visualization so Matplotlib is a must have data visualization package and it can just make data visualization so easy and also so professional of course the beginner can only start with very simple plots but the experts can make all kinds of customization for Matplotlib so in order to do that let's go from a setup we are going to import pandas and the numpy these two we have played with many times and then let's import the 3rd one import matplotlib.pyplot as plt so this will be the module and the plt will be the nickname whenever we call plt we are actually calling this package the next one is the data file so I have already uploaded the economy of US .CSV here which is the same dataset that we used for pandas and you can download the data file in this module and upload it to this panel and then you copy again you copy the path and then paste the path into here so that you can continue with me so we actually have already learned what this data frame looks like we basically have 40 around years of GDP, inflation unemployment, and also we learned we have inflation change decrease increase or no change so on and so forth let's start with a simple plot because I assume you're already familiar with the structure of the dataset we don't have to look into who is a numeric who is object or categorical let's jump into the data visualization directly let's start with a simple plot okay so we can see that we need to call from plt and call the plot() and in here we are actually using the positional keywords so this is actually corresponding to the x and then this is corresponding to the y and we can see that the x is in the year and the y is the GDP growth and we can see that by default if you call a plot directly from Matploltlib you are going to see a line plot links all the dots together and we can specify what is the label we need for the x, which is the year and what is the label we need for the y which is GDP growth and we can also specify the title of this plot which is economy of US my recommendation is always have the labels and the title along with the plot otherwise people will be confused about which attributes is x and y and which graph which plot represents what is the meaning or purpose of this plot so always have them ready when you create a plot from matplotlib because those things will not automatically be there you have to manually create them by yourself we can do some change of the markers for example here by default the markers will be the line so we see a line of the plot you can change the markers still use the year and the GDP growth but if you change the markers to 'o' you will see it's actually a scatter plot so the year and the growth and economy of US is the same but now we can see there is no line anymore but we see dots and actually I prepared all the possible markers just in case you like some of them and don't like some of them so this is all the markers and I'm going to show them one by one quickly and you of course you can read them later on when you have time so this is our scatter and this is the star and this is the smaller dots and this is tiny dots and this is the cross or x and this is another cross so on and so forth so basically as I said Matplotlib can provide a lot of customization depends on how you choose so you have so many different shapes of the dots you can choose and then I believe at least one of them will satisfy you and then you can even mix them so that you can show different relationship with different marks okay the next one is the line as we know that if we just use the x and the y and they are basically by default we'll be connected by a line however in this plot we can see that the x is year and the y is the growth and this 'l' is actually representing the Mark the line and the color so the Mark is the o which means we have these dots showing up there the line is how we connect them maybe missing like that scatter plot maybe like this one even though we show the dots but we want to connect them and also the last part is the color in this case we have the red so the lines specifies 1 2 3 4 different lines of how you connect the dots like this solid line like this dot line like this dash line like this dash and a dark line so on and so forth again you have so many choices and then the last part as you already see is the color so we can change the dots markers we can change the connection which is the line and then we can change the color of those dots and the line this red green blue are the choices you can have and then I list all of them here so that you can see them one by one so this will be the red and this will be the green blue so on and so forth of course this one will not be a good choice because you basically chose the white as the dots and the line and you can never see anything and we can also customize the marker size and we previously see that our marker can be the dots can be can be crossed can be tiny dots etc that is how we specify the markers and here we can specify the marker size as 15 so the marker will be a little bit larger and we can even make it smaller or larger depends on your needs and how you want to show the result okay so those are a very simple graph but we can customize it in a lot of ways the dots the connection the color and also the size of the dots let's see how we can make some different plots we can see that an df['Year'] and a df['GDP_growth'] as x and y and o which we know will be the dots or the scatter so this one is actually the same as the scatter plot and we can directly call the scatter plot rather than call from the plot and specify the o so there are just 2 things and we learned in pandas as well we can always call from plot directly but we can also call plot and scatter for a more specified utility in here you can see our plot scatter is a special plot so that you don't have to feel the o because scatter will be by default the o and we are going to also specifyi x and y and the title as well and similar to our pandas we have the color bar can be specified in matplotlib so you specify the df with the year as x and the growth as the y and you can assign the color equal to another dimension and then you can have the color map as the hot which means that how you are going to show the colors and in this case the hot color will be light and the cold color will be dark so we can see the 0 is dark and the 0.14 will be really bright because that will be the highest inflation we can see so again this is using a 2D graph to show 3 dimension information x and y and also inflation you can change the sides of the certain dots as well as another way to embed the 3rd dimension so we have the first dimension as year second dimension as GDP growth and how about if we want to embed the unemployment into the graph by using the different size of the dots for example if we see a small dot so that here we have a small unemployment a low unemployment if we see a high unemployment we have a larger dots so this is using the size of the dots as an argument for the scatter plot of course we can combine the color and the size so that you can see them in a 2D but use 4 dimension of information we can see the color bar represents inflation we can see the size represents unemployment and this alpha as another specified argument is actually you can change the overlap the alpha defines the transparency of the overlapping of your dots and we can do some other plots as well so we just learned all the scatter how about we do a bar. for the bar plot you just call plt.bar() specificly you can show the change of the GDP growth every year and you can do the histogram as well and you just call from the plt.hist() and then you fit in the certain attribute you want to show the histogram and then you get the result and we can change the bin from the default 10 to 50 if you like to get more detailed information and for the matplotlib we can also do the pie plot for the pie plot you can see always go from the value_counts() because this one provides a series or data frame and then we can go from that data frame onto the pie plot and give them labels, assign the legend, and give the title because the pie plot has no x and y but the pie plot does need the legend so that we know which color represents which label for the pie plot, in matplotlib, we can do something like explode for example if we are talking about the increasement of inflation change then we can specify this piece of the pie is the one we are focusing and then we can have explode is 0 0.2 and 0 to make this one stand out we can also do the box plot for the outlier detection and for the central tendency and the dispersion estimation as well so this will be the same as the panda's box plots and for matplotlib, we have a violinplot and that will be something a little bit different that violinplot shows first of all the distribution of the inflation and in the distribution where I can actually show similar to our kde, that show the frequency of the counts of the certain value at the same time because for the box plot we don't know which value has the most account we only know this box represents Q3 Q2 and Q1 but for the violin rather than just to show that quantiles we can show the distribution or the density of your value at the same time so that will be very useful sometimes the other very handy way of doing matplotlib is do multi plots so for example we can show 3 plots at the same place so we can show the year as our x-axis and for the y we can show our GDP growth and inflation and our employment in here with 3 different colors of course this plot is not perfect it's because we actually don't know which line represents which attribute so you will have to add the legend. To add the legend you have to add the label of the legend for that particular plot first then when you call the legend you are going to find out the legend shows up here and the y label shows up here and years shows up here but for the y, because the y is a general measurement of all the 3 combined so it will actually be a label you are going to customize here may not be actually in your dataset another one is the grid because the grid will be helpful if your user want to know exactly the estimation of this point what it is in terms of the year we can quickly go here maybe 2009 or 2008 and what is the inflation and we can quickly go here in terms of the 0.75 because this grid gives you the benchmark of how we can compare we can also change the arrangement of the plots if we have multiple ones in one place and it will look like a little bit overwhelming but actually it is quite simple first of all you need to define the sub plot this one is actually defining 3 * 1 matrix if you are going to put the sub plot in 3 * 1 that means that we have 3 rows and 1 column so you are going to get 3 plots stacked together and then these last 1 specifies this subplot will be the first one get into this stack of plots we can see that is the first subplot GDP_growth and the label GDP_growth as our legend the second one will be 3 *1 following the same structure and then that will be the second plot we put in so we get the middle plot in as the inflation and the last one is 3 * 1 and 3 which means that we are put that into a 3 * 1 matrix and the last one, so that is our employment if you like to compare them not in this stacking way you want to change the direction then you can also specify the matrix of 1 by 3 so that you will have them lined together like this so you will get 1 row and 3 column this is the 1st one 2nd one and 3rd one so there are many many ways of how you can customize matplotlib again, the documentation I already showed at the beginning that is this matplotlib.org welcome to check them out and find more tutorials